/////
// appendix_tables.do
// This file creates the tables in the appendix.
// The input file is localauthority_level.dta. 
/////

/////
// Table D.1: Dependent variable summary statistics.
/////

* open local authority-level data
use "localauthority_level.dta", clear 

* summary stats for dvs
estpost summarize perchired perchired19 perchired1020
esttab using "summarytable_dv.tex", replace alignment(c) ///
			 cells((count mean(fmt(3)) sd(fmt(3)) min(fmt(3)) max(fmt(3)))) noobs ///
			 collabels("Variable" "Count" "Mean" "Standard deviation" "Minimum" "Maximum") ///
			 title("Dependent variable summary statistics") ///
			 varlabels(perchired "Hired" perchired19 "Hired (1-9)" perchired1020 "Hired (10-20)")
	
/////
// Table D.2: Independent variable summary statistics.
/////

* open local authority-level data
use "localauthority_level.dta", clear 

* summary stats for dvs
estpost summarize majority la_clerk clerketh mpeth clerk_first_year
esttab using "summarytable_iv.tex", replace alignment(c) ///
			 cells((count mean(fmt(3)) sd(fmt(3)) min(fmt(3)) max(fmt(3)))) noobs ///
			 collabels("" "Count" "Mean" "Standard deviation" "Minimum" "Maximum") ///
			 title("Independent variable summary statistics") ///
			 varlabels(majority "Majority" la_clerk "Clerk presence" ///
					   clerketh "Clerk ethnicity" mpeth "MP ethnicity" clerk_first_year "Clerk first year")

/////
// Table G.1: Hiring iteratively adding independent variables.
/////

* open local authority-level data
use "localauthority_level.dta", clear 
est clear

* define dependent variable 
local depvar hired 
	
* model with ethnic group-locality and year fixed effects (only majority)
local indvar "c.majority##c.perc`depvar'miss"
quietly reghdfe perc`depvar' `indvar', absorb(TERETHid year) vce(cluster territory_level) // ethnic group-locality and year fixed effects
	est store model_perc`depvar'_m1
	estadd local TERETH "Yes"
	estadd local ETHYEAR "No"
	estadd local year "Yes"
	estadd local TERYEAR "No"
	* calculate linear combinations and other stats 
		* j is non-coethnic with the maj
		summarize perc`depvar' if majority == 0 
		estadd scalar noclerk_majnoteth = r(mean)				
		* outcome mean
		gen used_d`depvar' = e(sample)
		summarize perc`depvar' if used_d`depvar' == 1
		estadd scalar outcome_mean = r(mean)
		estfe model_perc`depvar'_m1, labels(TERETHid "Locality-ethnicity FE" year "Year FE" ETHYEARid "Ethnicity-year FE" TERYEARid "Locality-year FE")
		drop used*
		
* model with ethnic group-locality and year fixed effects (majority + clerk presence + clerk ethnicity) 
local indvar "c.majority##c.perc`depvar'miss c.la_clerk##c.perc`depvar'miss c.clerketh##c.perc`depvar'miss"
quietly reghdfe perc`depvar' `indvar', absorb(TERETHid year) vce(cluster territory_level) // ethnic group-locality and year fixed effects
	est store model_perc`depvar'_m2
	estadd local TERETH "Yes"
	estadd local ETHYEAR "No"
	estadd local year "Yes"
	estadd local TERYEAR "No"
	* calculate linear combinations and other stats 
		* no clerk and j is non co-ethnic with the council
		summarize perc`depvar' if majority == 0 & la_clerk == 0 
		estadd scalar noclerk_majnoteth = r(mean)				
		* outcome mean
		gen used_d`depvar' = e(sample)
		summarize perc`depvar' if used_d`depvar' == 1
		estadd scalar outcome_mean = r(mean)
		estfe model_perc`depvar'_m2, labels(TERETHid "Locality-ethnicity FE" year "Year FE" ETHYEARid "Ethnicity-year FE" TERYEARid "Locality-year FE")
		drop used*
		
* model with ethnic group-locality and year fixed effects (majority + clerk presence + clerk ethnicity)
local indvar "c.majority##c.la_clerk##c.clerketh##c.perc`depvar'miss"
quietly reghdfe perc`depvar' `indvar', absorb(TERETHid year) vce(cluster territory_level) // ethnic group-locality and year fixed effects
	est store model_perc`depvar'_m3
	estadd local TERETH "Yes"
	estadd local ETHYEAR "No"
	estadd local year "Yes"
	estadd local TERYEAR "No"
	* calculate linear combinations and other stats 
		* no clerk and j is non co-ethnic with the council
		summarize perc`depvar' if majority == 0 & la_clerk == 0 & clerketh == 0 
		estadd scalar noclerk_majnoteth = r(mean)				
		* outcome mean
		gen used_d`depvar' = e(sample)
		summarize perc`depvar' if used_d`depvar' == 1
		estadd scalar outcome_mean = r(mean)
		estfe model_perc`depvar'_m3, labels(TERETHid "Locality-ethnicity FE" year "Year FE" ETHYEARid "Ethnicity-year FE" TERYEARid "Locality-year FE")
		drop used*

* create Table G.1 
esttab model_perchired_m1 model_perchired_m2 model_perchired_m3 using "table_g1.tex", replace ///
	   booktabs b(3) se(3) eqlabels(none) alignment(c) ///
	   stats(outcome_mean N r2 ///
			 TERETH year ETHYEAR TERYEAR, ///
			 fmt(3 0 3) label("Outcome Mean" "Observations" "R-Squared" ///
				   "Locality-ethnicity FE" "Year FE" "Ethnicity-year FE" "Locality-year FE")) ///
	   collabels(,lhs(Outcome:)) ///
	   label mtitle("Hiring" "Hiring" "Hiring") nonumbers ///
	   varlabels(majority "Majority" la_clerk "Clerk presence" c.majority#c.la_clerk "Majority x Clerk presence" ///
				clerketh "Clerk ethnicity" c.majority#c.clerketh "Majority x Clerk ethnicity" ///
				perchiredmiss "Missing indicator" c.majority#c.perchiredmiss "Majority x Missing indicator" ///
				c.la_clerk#c.perchiredmiss "Clerk presence x Missing indicator" ///
				c.majority#c.la_clerk#c.perchiredmiss "Majority x Clerk presence x Missing indicator" ///
				c.clerketh#c.perchiredmiss "Clerk ethnicity x Missing indicator" ///
				c.majority#c.clerketh#c.perchiredmiss "Majority x Clerk ethnicity x Missing indicator") ///
	   keep(majority la_clerk c.majority#c.la_clerk clerketh c.majority#c.clerketh ///
			perchiredmiss c.majority#c.perchiredmiss c.la_clerk#c.perchiredmiss ///
			c.majority#c.la_clerk#c.perchiredmiss c.majority#c.clerketh#c.perchiredmiss c.clerketh#c.perchiredmiss ) ///
	   star(* 0.10 ** 0.05 *** 0.01)	 

/////
// Table G.2: Number of hires (i.e., levels instead of percents)
/////

* open local authority-level data
use "localauthority_level.dta", clear 
est clear

* define dependent variable
local depvar hired 
	
* model with ethnic group-locality and year fixed effects
local indvar "c.majority##c.la_clerk##c.clerketh"
quietly reghdfe `depvar' `indvar', absorb(TERETHid year) vce(cluster territory_level) // ethnic group-locality and year fixed effects
	est store model_`depvar'_m1
	estadd local TERETH "Yes"
	estadd local ETHYEAR "No"
	estadd local year "Yes"
	estadd local TERYEAR "No"
	* calculate linear combinations and other stats 
		* no clerk and j is non co-ethnic with the council
		summarize `depvar' if majority == 0 & la_clerk == 0 & clerketh == 0 
		estadd scalar noclerk_majnoteth = r(mean)				
		* no clerk and j is co-ethnic with the council
		est restore model_`depvar'_m1
		lincomest _b[majority] 
		estadd scalar noclerk_majeth = r(estimate)
		estadd scalar noclerk_majeth_se = r(se)
		est store m1_lincom1
		* j is non-coethnic with the clerk and the council
		est restore model_`depvar'_m1
		lincomest _b[la_clerk] 
		estadd scalar clerknoteth_majnoteth = r(estimate)
		estadd scalar clerknoteth_majnoteth_se = r(se)
		est store m1_lincom2
		* j is non co-ethnic with the clerk, but co-ethnic with the council
		est restore model_`depvar'_m1
		lincomest _b[majority] + _b[la_clerk] + _b[c.majority#c.la_clerk]
		estadd scalar clerknoteth_majeth = r(estimate)
		estadd scalar clerknoteth_majeth_se = r(se)
		est store m1_lincom3
		* j is co-ethnic with the clerk, but not with the council
		est restore model_`depvar'_m1
		lincomest _b[la_clerk] + _b[clerketh]
		estadd scalar clerketh_majnoteth = r(estimate)
		estadd scalar clerketh_majnoteth_se = r(se)
		est store m1_lincom4
		* j is co-ethnic with the clerk and the council 
		est restore model_`depvar'_m1
		lincomest _b[majority] + _b[la_clerk] + _b[c.majority#c.la_clerk] + _b[clerketh] + _b[c.majority#c.clerketh]
		estadd scalar clerketh_majeth = r(estimate)
		estadd scalar clerketh_majeth_se = r(se)
		est store m1_lincom5
		* outcome mean and other stats
		gen used_d`depvar' = e(sample)
		summarize `depvar' if used_d`depvar' == 1
		estadd scalar outcome_mean = r(mean)
		estfe model_`depvar'_m1, labels(TERETHid "Locality-ethnicity FE" year "Year FE" ETHYEARid "Ethnicity-year FE" TERYEARid "Locality-year FE")
		drop used*
	
* model with ethnic group-locality, ethnic group-year, and locality-year fixed effects
quietly reghdfe `depvar' `indvar', absorb(TERETHid ETHYEARid TERYEARid) vce(cluster territory_level) // ethnic group-year and locality-year fixed effects
	est store model_`depvar'_m2
	estadd local TERETH "Yes"
	estadd local ETHYEAR "Yes"
	estadd local year "No"
	estadd local TERYEAR "Yes"
	* calculate linear combinations and other stats 
		* no clerk and j is co-ethnic with the council
		est restore model_`depvar'_m2
		lincomest _b[majority] 
		estadd scalar noclerk_majeth = r(estimate)
		estadd scalar noclerk_majeth_se = r(se)
		est store m2_lincom1
		* j is non-coethnic with the clerk and the council
		est restore model_`depvar'_m2
		lincomest _b[la_clerk] 
		estadd scalar clerknoteth_majnoteth = r(estimate)
		estadd scalar clerknoteth_majnoteth_se = r(se)
		est store m2_lincom2
		* j is non co-ethnic with the clerk, but co-ethnic with the council
		est restore model_`depvar'_m2
		lincomest  _b[majority] + _b[la_clerk] + _b[c.majority#c.la_clerk]
		estadd scalar clerknoteth_majeth = r(estimate)
		estadd scalar clerknoteth_majeth_se = r(se)
		est store m2_lincom3
		* j is co-ethnic with the clerk, but not with the council
		est restore model_`depvar'_m2
		lincomest _b[la_clerk] + _b[clerketh]
		estadd scalar clerketh_majnoteth = r(estimate)
		estadd scalar clerketh_majnoteth_se = r(se)
		est store m2_lincom4
		* j is co-ethnic with the clerk and the council 
		est restore model_`depvar'_m2
		lincomest _b[majority] + _b[la_clerk] + _b[c.majority#c.la_clerk] + _b[clerketh] + _b[c.majority#c.clerketh]
		estadd scalar clerketh_majeth = r(estimate)
		estadd scalar clerketh_majeth_se = r(se)
		est store m2_lincom5
		* outcome mean and other stats
		gen used_d`depvar' = e(sample)
		sum `depvar' if used_d`depvar' == 1
		estadd scalar outcome_mean = r(mean)
		estfe model_`depvar'_m2, labels(TERETHid "Locality-ethnicity FE" year "Year FE" ETHYEARid "Ethnicity-year FE" TERYEARid "Locality-year FE")
		drop used*
			
* create Table G.2 
esttab model_hired_m1 model_hired_m2 using "table_g2.tex", replace ///
	   booktabs b(3) se(3) eqlabels(none) alignment(c) ///
	   stats(outcome_mean N r2 ///
			 TERETH year ETHYEAR TERYEAR, ///
			 fmt(3 0 3) label("Outcome Mean" "Observations" "R-Squared" ///
				   "Locality-ethnicity FE" "Year FE" "Ethnicity-year FE" "Locality-year FE")) ///
	   collabels(,lhs(Outcome:)) ///
	   label mtitle("Number of hires" "Number of hires") nonumbers ///
	   varlabels(majority "Majority" la_clerk "Clerk presence" c.majority#c.la_clerk "Majority x Clerk presence" ///
				clerketh "Clerk ethnicity" c.majority#c.clerketh "Majority x Clerk ethnicity") ///
	   keep(majority la_clerk c.majority#c.la_clerk clerketh c.majority#c.clerketh) ///
	   star(* 0.10 ** 0.05 *** 0.01)

/////
// Table G.3: Interaction with president's ethnicity (Kikuyu)
/////

* open local authority-level data
use "localauthority_level.dta", clear 
est clear

* create a la / year id
egen layear_id = group(territory_level year)

* create kikuyumaj
gen kikuyumaj = .
replace kikuyumaj = 1 if ethnicity == "KIKUYU" & majority == 1
xfill kikuyumaj, i(layear_id)
replace kikuyumaj = 0 if kikuyumaj != 1

* define dependent variable
local depvar hired

* model with ethnic group-locality and year fixed effects
local indvar "c.majority##c.clerketh##c.la_clerk##c.perc`depvar'miss##c.kikuyumaj"
quietly reghdfe perc`depvar' `indvar', absorb(TERETHid year) vce(cluster territory_level) // ethnic group-locality and year fixed effects
		est store model_perc`depvar'_m1
		estadd local TERETH "Yes"
		estadd local ETHYEAR "No"
		estadd local year "Yes"
		estadd local TERYEAR "No"
		* outcome mean and other stats 
		gen used_d`depvar' = e(sample)
		quietly sum perc`depvar' if used_d`depvar' == 1
		estadd scalar outcome_mean = r(mean)
		estfe model_perc`depvar'_m1, labels(TERETHid "Locality-ethnicity FE" year "Year FE" ETHYEARid "Ethnicity-year FE" TERYEARid "Locality-year FE")
		drop used*

* model with ethnic group-locality, ethnic group-year, and locality-year fixed effects
quietly reghdfe perc`depvar' `indvar', absorb(TERETHid ETHYEARid TERYEARid) vce(cluster territory_level) // ethnic group-year and locality-year fixed effects
		est store model_perc`depvar'_m2
		estadd local TERETH "Yes"
		estadd local ETHYEAR "Yes"
		estadd local year "No"
		estadd local TERYEAR "Yes"
		* outcome mean and other stats 
		gen used_d`depvar' = e(sample)
		sum perc`depvar' if used_d`depvar' == 1
		estadd scalar outcome_mean = r(mean)
		estfe model_perc`depvar'_m2, labels(TERETHid "Locality-ethnicity FE" year "Year FE" ETHYEARid "Ethnicity-year FE" TERYEARid "Locality-year FE")
		drop used*

* create Table G.3 
esttab model_perchired_m1 model_perchired_m2 using "table_g3.tex", replace ///
	   booktabs b(3) se(3) eqlabels(none) alignment(c) ///
	   stats(outcome_mean N r2 ///
			 TERETH year ETHYEAR TERYEAR, ///
			 fmt(3 0 3) label("Outcome Mean" "Observations" "R-Squared" ///
				   "Locality-ethnicity FE" "Year FE" "Ethnicity-year FE" "Locality-year FE")) ///
	   label mtitle("Hired" "Hired") ///
	   varlabels(majority "Majority" clerketh "Clerk ethnicity" la_clerk "Clerk presence" kikuyumaj "President's ethnicity" ///
				 c.majority#c.clerketh "Majority x Clerk ethnicity" c.majority#c.la_clerk "Majority x Clerk presence" c.majority#c.kikuyumaj "Majority x President's ethnicity" ///
				 c.la_clerk#c.kikuyumaj "Clerk presence x President's ethnicity" c.clerketh#c.kikuyumaj "Clerk ethnicity x President's ethnicity" ///
				 c.majority#c.clerketh#c.kikuyumaj "Majority x Clerk ethnicity x President's ethnicity" c.majority#c.la_clerk#c.kikuyumaj "Majority x Clerk presence x President's ethnicity" ///
				 perchiredmiss "Missing indicator" ///
				 c.majority#c.perchiredmiss "Majority x Missing indicator" ///
				 c.clerketh#c.perchiredmiss "Clerk ethnicity x Missing indicator" ///
				 c.majority#c.clerketh#c.perchiredmiss "Majority x Clerk ethnicity x Missing indicator" ///
				 c.la_clerk#c.perchiredmiss "Clerk presence x Missing indicator" ///
				 c.majority#c.la_clerk#c.perchiredmiss "Majority x Clerk presence x Missing indicator" ///
				 c.perchiredmiss#c.kikuyumaj "Missing indicator x President's ethnicity" ///
				 c.majority#c.perchiredmiss#c.kikuyumaj "Majority x President's ethnicity x Missing indicator" ///
				 c.clerketh#c.perchiredmiss#c.kikuyumaj "Clerk ethnicity x President's ethnicity x Missing indicator" ///
				 c.la_clerk#c.perchiredmiss#c.kikuyumaj "Clerk presence x President's ethnicity x Missing indicator" ///
				 c.majority#c.la_clerk#c.perchiredmiss#c.kikuyumaj "Majority x Clerk presence x President's ethnicity x Missing indicator" ///
				 c.majority#c.clerketh#c.perchiredmiss#c.kikuyumaj "Majority x Clerk ethnicity x President's ethnicity x Missing indicator") ///
				 	   collabels(,lhs(Outcome:)) ///
	   keep(majority clerketh la_clerk kikuyumaj ///
			c.majority#c.clerketh c.majority#c.la_clerk c.majority#c.kikuyumaj c.la_clerk#c.kikuyumaj c.clerketh#c.kikuyumaj ///
			c.majority#c.clerketh#c.kikuyumaj c.majority#c.la_clerk#c.kikuyumaj ///
			perchiredmiss c.majority#c.perchiredmiss ///
		    c.clerketh#c.perchiredmiss c.majority#c.clerketh#c.perchiredmiss ///
			c.la_clerk#c.perchiredmiss c.majority#c.la_clerk#c.perchiredmiss ///
			c.perchiredmiss#c.kikuyumaj c.majority#c.perchiredmiss#c.kikuyumaj ///
			c.clerketh#c.perchiredmiss#c.kikuyumaj c.la_clerk#c.perchiredmiss#c.kikuyumaj ///
			c.majority#c.la_clerk#c.perchiredmiss#c.kikuyumaj ///
			c.majority#c.clerketh#c.perchiredmiss#c.kikuyumaj) ///
	   star(* 0.10 ** 0.05 *** 0.01) 
		
/////
// Table G.4: Interaction with Minister of Local Goverment's ethnicity
/////

* open local authority-level data
use "localauthority_level.dta", clear 
est clear

* create a la / year id
egen layear_id = group(territory_level year)

* create an indicator for co-ethnic of the min of local gov
gen minlocalgov_eth = .
replace minlocalgov_eth = 1 if majority == 1 & ethnicity == "LUHYA" & year <= 2007
replace minlocalgov_eth = 1 if majority == 1 & ethnicity == "LUO" & year >= 2008
xfill minlocalgov_eth, i(layear_id)
replace minlocalgov_eth = 0 if minlocalgov_eth == .

* define dependent variable
local depvar hired

* model with ethnic group-locality and year fixed effects
local indvar "c.majority##c.clerketh##c.la_clerk##c.perc`depvar'miss##c.minlocalgov_eth"
quietly reghdfe perc`depvar' `indvar', absorb(TERETHid year) vce(cluster territory_level) // ethnic group-locality and year fixed effects
		est store model_perc`depvar'_m1
		estadd local TERETH "Yes"
		estadd local ETHYEAR "No"
		estadd local year "Yes"
		estadd local TERYEAR "No"
		* outcome mean and other stats 
		gen used_d`depvar' = e(sample)
		quietly sum perc`depvar' if used_d`depvar' == 1
		estadd scalar outcome_mean = r(mean)
		estfe model_perc`depvar'_m1, labels(TERETHid "Locality-ethnicity FE" year "Year FE" ETHYEARid "Ethnicity-year FE" TERYEARid "Locality-year FE")
		drop used*

* model with ethnic group-locality, ethnic group-year, and locality-year fixed effects
quietly reghdfe perc`depvar' `indvar', absorb(TERETHid ETHYEARid TERYEARid) vce(cluster territory_level) // ethnic group-year and locality-year fixed effects
		est store model_perc`depvar'_m2
		estadd local TERETH "Yes"
		estadd local ETHYEAR "Yes"
		estadd local year "No"
		estadd local TERYEAR "Yes"
		* outcome mean and other stats 		
		gen used_d`depvar' = e(sample)
		sum perc`depvar' if used_d`depvar' == 1
		estadd scalar outcome_mean = r(mean)
		estfe model_perc`depvar'_m2, labels(TERETHid "Locality-ethnicity FE" year "Year FE" ETHYEARid "Ethnicity-year FE" TERYEARid "Locality-year FE")
		drop used*

* create Table G.4
esttab model_perchired_m1 model_perchired_m2 using "table_g4.tex", replace ///
	   booktabs b(3) se(3) eqlabels(none) alignment(c) ///
	   stats(outcome_mean N r2 ///
			 TERETH year ETHYEAR TERYEAR, ///
			 fmt(3 0 3) label("Outcome Mean" "Observations" "R-Squared" ///
				   "Locality-ethnicity FE" "Year FE" "Ethnicity-year FE" "Locality-year FE")) ///
	   label mtitle("Hired" "Hired") ///
	   varlabels(majority "Majority" clerketh "Clerk ethnicity" la_clerk "Clerk presence" minlocalgov_eth "Minister's ethnicity" ///
				 c.majority#c.clerketh "Majority x Clerk ethnicity" c.majority#c.la_clerk "Majority x Clerk presence" c.majority#c.minlocalgov_eth "Majority x Minister's ethnicity" ///
				 c.la_clerk#c.minlocalgov_eth "Clerk presence x Minister's ethnicity" c.clerketh#c.minlocalgov_eth "Clerk ethnicity x Minister's ethnicity" ///
				 c.majority#c.clerketh#c.minlocalgov_eth "Majority x Clerk ethnicity x Minister's ethnicity" c.majority#c.la_clerk#c.minlocalgov_eth "Majority x Clerk presence x Minister's ethnicity" ///
				 perchiredmiss "Missing indicator" ///
				 c.majority#c.perchiredmiss "Majority x Missing indicator" ///
				 c.clerketh#c.perchiredmiss "Clerk ethnicity x Missing indicator" ///
				 c.majority#c.clerketh#c.perchiredmiss "Majority x Clerk ethnicity x Missing indicator" ///
				 c.la_clerk#c.perchiredmiss "Clerk presence x Missing indicator" ///
				 c.majority#c.la_clerk#c.perchiredmiss "Majority x Clerk presence x Missing indicator" ///
				 c.perchiredmiss#c.minlocalgov_eth "Minister's ethnicity x Missing indicator" ///
				 c.majority#c.perchiredmiss#c.minlocalgov_eth "Majority x Minister's ethnicity x Missing indicator" ///
				 c.clerketh#c.perchiredmiss#c.minlocalgov_eth "Clerk ethnicity x Minister's ethnicity x Missing indicator" ///
				 c.la_clerk#c.perchiredmiss#c.minlocalgov_eth "Clerk presence x Minister's ethnicity x Missing indicator" ///
				 c.majority#c.la_clerk#c.perchiredmiss#c.minlocalgov_eth "Majority x Clerk presence x Minister's ethnicity x Missing indicator" ///
				 c.majority#c.clerketh#c.perchiredmiss#c.minlocalgov_eth "Majority x Clerk ethnicity x Minister's ethnicity x Missing indicator") ///
				 	   collabels(,lhs(Outcome:)) ///
	   keep(majority clerketh la_clerk minlocalgov_eth ///
			c.majority#c.clerketh c.majority#c.la_clerk c.majority#c.minlocalgov_eth c.la_clerk#c.minlocalgov_eth c.clerketh#c.minlocalgov_eth ///
			c.majority#c.clerketh#c.minlocalgov_eth c.majority#c.la_clerk#c.minlocalgov_eth ///
			perchiredmiss c.majority#c.perchiredmiss ///
		    c.clerketh#c.perchiredmiss c.majority#c.clerketh#c.perchiredmiss ///
			c.la_clerk#c.perchiredmiss c.majority#c.la_clerk#c.perchiredmiss ///
			c.perchiredmiss#c.minlocalgov_eth c.majority#c.perchiredmiss#c.minlocalgov_eth ///
			c.clerketh#c.perchiredmiss#c.minlocalgov_eth c.la_clerk#c.perchiredmiss#c.minlocalgov_eth ///
			c.majority#c.la_clerk#c.perchiredmiss#c.minlocalgov_eth ///
			c.majority#c.clerketh#c.perchiredmiss#c.minlocalgov_eth) ///
	   star(* 0.10 ** 0.05 *** 0.01) 

/////
// Table G.5: Interaction with MP ethnicity
/////

* open local authority-level data
use "localauthority_level.dta", clear 
est clear

* define dependant variable
local depvar hired

* model with ethnic group-locality and year fixed effects
local indvar "c.majority##c.clerketh##c.la_clerk##c.perc`depvar'miss##c.mpeth"
quietly reghdfe perc`depvar' `indvar', absorb(TERETHid year) vce(cluster territory_level) // ethnic group-locality and year fixed effects
		est store model_perc`depvar'_m1
		estadd local TERETH "Yes"
		estadd local ETHYEAR "No"
		estadd local year "Yes"
		estadd local TERYEAR "No"
		* outcome and other stats
		gen used_d`depvar' = e(sample)
		quietly sum perc`depvar' if used_d`depvar' == 1
		estadd scalar outcome_mean = r(mean)
		estfe model_perc`depvar'_m1, labels(TERETHid "Locality-ethnicity FE" year "Year FE" ETHYEARid "Ethnicity-year FE" TERYEARid "Locality-year FE")
		drop used*

* model with ethnic group-locality, ethnic group-year, and locality-year fixed effects
quietly reghdfe perc`depvar' `indvar', absorb(TERETHid ETHYEARid TERYEARid) vce(cluster territory_level) // ethnic group-year and locality-year fixed effects
		est store model_perc`depvar'_m2
		estadd local TERETH "Yes"
		estadd local ETHYEAR "Yes"
		estadd local year "No"
		estadd local TERYEAR "Yes"
		* outcome and other stats
		gen used_d`depvar' = e(sample)
		sum perc`depvar' if used_d`depvar' == 1
		estadd scalar outcome_mean = r(mean)
		estfe model_perc`depvar'_m2, labels(TERETHid "Locality-ethnicity FE" year "Year FE" ETHYEARid "Ethnicity-year FE" TERYEARid "Locality-year FE")
		drop used*

* create Table G.5
esttab model_perchired_m1 model_perchired_m2 using "table_g5.tex", replace ///
	   booktabs b(3) se(3) eqlabels(none) alignment(c) ///
	   stats(outcome_mean N r2 ///
			 TERETH year ETHYEAR TERYEAR, ///
			 fmt(3 0 3) label("Outcome Mean" "Observations" "R-Squared" ///
				   "Locality-ethnicity FE" "Year FE" "Ethnicity-year FE" "Locality-year FE")) ///
	   label mtitle("Hired" "Hired") ///
	   varlabels(majority "Majority" clerketh "Clerk ethnicity" la_clerk "Clerk presence" mpeth "MP ethnicity" ///
				 c.majority#c.clerketh "Majority x Clerk ethnicity" c.majority#c.la_clerk "Majority x Clerk presence" c.majority#c.mpeth "Majority x MP ethnicity" ///
				 c.la_clerk#c.mpeth "Clerk presence x MP ethnicity" c.clerketh#c.mpeth "Clerk ethnicity x MP ethnicity" ///
				 c.majority#c.clerketh#c.mpeth "Majority x Clerk ethnicity x MP ethnicity" c.majority#c.la_clerk#c.mpeth "Majority x Clerk presence x MP ethnicity" ///
				 perchiredmiss "Missing indicator" ///
				 c.majority#c.perchiredmiss "Majority x Missing indicator" ///
				 c.clerketh#c.perchiredmiss "Clerk ethnicity x Missing indicator" ///
				 c.majority#c.clerketh#c.perchiredmiss "Majority x Clerk ethnicity x Missing indicator" ///
				 c.la_clerk#c.perchiredmiss "Clerk presence x Missing indicator" ///
				 c.majority#c.la_clerk#c.perchiredmiss "Majority x Clerk presence x Missing indicator" ///
				 c.perchiredmiss#c.mpeth "Missing indicator x MP ethnicity" ///
				 c.majority#c.perchiredmiss#c.mpeth "Majority x MP ethnicity x Missing indicator" ///
				 c.clerketh#c.perchiredmiss#c.mpeth "Clerk ethnicity x MP ethnicity x Missing indicator" ///
				 c.la_clerk#c.perchiredmiss#c.mpeth "Clerk presence x MP ethnicity x Missing indicator" ///
				 c.majority#c.la_clerk#c.perchiredmiss#c.mpeth "Majority x Clerk presence x MP ethnicity x Missing indicator" ///
				 c.majority#c.clerketh#c.perchiredmiss#c.mpeth "Majority x Clerk ethnicity x MP ethnicity x Missing indicator") ///
				 	   collabels(,lhs(Outcome:)) ///
	   keep(majority clerketh la_clerk mpeth ///
			c.majority#c.clerketh c.majority#c.la_clerk c.majority#c.mpeth c.la_clerk#c.mpeth c.clerketh#c.mpeth ///
			c.majority#c.clerketh#c.mpeth c.majority#c.la_clerk#c.mpeth ///
			perchiredmiss c.majority#c.perchiredmiss ///
		    c.clerketh#c.perchiredmiss c.majority#c.clerketh#c.perchiredmiss ///
			c.la_clerk#c.perchiredmiss c.majority#c.la_clerk#c.perchiredmiss ///
			c.perchiredmiss#c.mpeth c.majority#c.perchiredmiss#c.mpeth ///
			c.clerketh#c.perchiredmiss#c.mpeth c.la_clerk#c.perchiredmiss#c.mpeth ///
			c.majority#c.la_clerk#c.perchiredmiss#c.mpeth ///
			c.majority#c.clerketh#c.perchiredmiss#c.mpeth) ///
	   star(* 0.10 ** 0.05 *** 0.01) 	
  
/////
// Table G.6-G.8: Table 3 interacted with clerk's first year in a local authority 
/////

* open local authority-level data
use "localauthority_level.dta", clear 
est clear

* define dependent variables
local depvar hired hired19 hired1020

* re-estimate models for table 3 of the main paper
local depvar hired hired19 hired1020
foreach i of local depvar {
		
	* model with ethnic group-locality and year fixed effects
	local indvar "c.majority##c.la_clerk##c.clerketh##c.perc`i'miss"
	quietly reghdfe perc`i' `indvar', absorb(TERETHid year) vce(cluster territory_level) // ethnic group-locality and year fixed effects
		est store table1_perc`i'_m1
		estadd local TERETH "Yes"
		estadd local ETHYEAR "No"
		estadd local year "Yes"
		estadd local TERYEAR "No"
		* linear combinations and other stats
			* no clerk and j is co-ethnic with the council
			est restore table1_perc`i'_m1
			lincomest _b[majority] 
			estadd scalar noclerk_majeth = r(estimate)
			estadd scalar noclerk_majeth_se = r(se)
			est store m1_lincom1
			* j is non-coethnic with the clerk and the council
			est restore table1_perc`i'_m1
			lincomest _b[la_clerk] 
			estadd scalar clerknoteth_majnoteth = r(estimate)
			estadd scalar clerknoteth_majnoteth_se = r(se)
			est store m1_lincom2
			* j is non co-ethnic with the clerk, but co-ethnic with the council
			est restore table1_perc`i'_m1
			lincomest _b[majority] + _b[la_clerk] + _b[c.majority#c.la_clerk]
			estadd scalar clerknoteth_majeth = r(estimate)
			estadd scalar clerknoteth_majeth_se = r(se)
			est store m1_lincom3
			* j is co-ethnic with the clerk, but not with the council
			est restore table1_perc`i'_m1
			lincomest _b[la_clerk] + _b[clerketh]
			estadd scalar clerketh_majnoteth = r(estimate)
			estadd scalar clerketh_majnoteth_se = r(se)
			est store m1_lincom4
			* j is co-ethnic with the clerk and the council 
			est restore table1_perc`i'_m1
			lincomest _b[majority] + _b[la_clerk] + _b[c.majority#c.la_clerk] + _b[clerketh] + _b[c.majority#c.clerketh]
			estadd scalar clerketh_majeth = r(estimate)
			estadd scalar clerketh_majeth_se = r(se)
			est store m1_lincom5
			* outcome mean and other stats
			gen used_d`i' = e(sample)
			quietly sum perc`i' if used_d`i' == 1
			estadd scalar outcome_mean = r(mean)
			estfe table1_perc`i'_m1, labels(TERETHid "Locality-ethnicity FE" year "Year FE" ETHYEARid "Ethnicity-year FE" TERYEARid "Locality-year FE")
			drop used*
	
	* model with ethnic group-locality, ethnic group-year, and locality-year fixed effects
	quietly reghdfe perc`i' `indvar', absorb(TERETHid ETHYEARid TERYEARid) vce(cluster territory_level) // ethnic group-year and locality-year fixed effects
		est store table1_perc`i'_m2
		estadd local TERETH "Yes"
		estadd local ETHYEAR "Yes"
		estadd local year "No"
		estadd local TERYEAR "Yes"
		* linear combinations and other stats
			* no clerk and j is co-ethnic with the council
			est restore table1_perc`i'_m2
			lincomest _b[majority] 
			estadd scalar noclerk_majeth = r(estimate)
			estadd scalar noclerk_majeth_se = r(se)
			est store m2_lincom1
			* j is non-coethnic with the clerk and the council
			est restore table1_perc`i'_m2
			lincomest _b[la_clerk] 
			estadd scalar clerknoteth_majnoteth = r(estimate)
			estadd scalar clerknoteth_majnoteth_se = r(se)
			est store m2_lincom2
			* j is non co-ethnic with the clerk, but co-ethnic with the council
			est restore table1_perc`i'_m2
			lincomest  _b[majority] + _b[la_clerk] + _b[c.majority#c.la_clerk]
			estadd scalar clerknoteth_majeth = r(estimate)
			estadd scalar clerknoteth_majeth_se = r(se)
			est store m2_lincom3
			* j is co-ethnic with the clerk, but not with the council
			est restore table1_perc`i'_m2
			lincomest _b[la_clerk] + _b[clerketh]
			estadd scalar clerketh_majnoteth = r(estimate)
			estadd scalar clerketh_majnoteth_se = r(se)
			est store m2_lincom4
			* j is co-ethnic with the clerk and the council 
			est restore table1_perc`i'_m2
			lincomest _b[majority] + _b[la_clerk] + _b[c.majority#c.la_clerk] + _b[clerketh] + _b[c.majority#c.clerketh]
			estadd scalar clerketh_majeth = r(estimate)
			estadd scalar clerketh_majeth_se = r(se)
			est store m2_lincom5
			* outcome mean and other stats
			gen used_d`i'_v`j' = e(sample)
			sum perc`i' if used_d`i' == 1
			estadd scalar outcome_mean = r(mean)
			estfe table1_perc`i'_m2, labels(TERETHid "Locality-ethnicity FE" year "Year FE" ETHYEARid "Ethnicity-year FE" TERYEARid "Locality-year FE")
			drop used*
			
}

* estimate models with clerk's first year
foreach i of local depvar {
	
	* indvar
	local indvar1 "c.majority##c.clerketh##c.la_clerk##c.perc`i'miss##c.clerk_first_year"
	local indvar2 "c.majority##c.clerketh##c.la_clerk##c.perc`i'miss##c.clerk_first_year_dm"
	
	* demean
	quietly reghdfe perc`i' `indvar1', absorb(TERETHid year) vce(cluster territory_level) // LA / ethnicity and year FEs, clustered at the LA level
	gen used_d`i' = e(sample)
	summarize clerk_first_year if used_d`i' == 1
	generate clerk_first_year_dm = clerk_first_year - r(mean)
	
	* model with ethnic group-locality and year fixed effects
	quietly reghdfe perc`i' `indvar2', absorb(TERETHid year) vce(cluster territory_level) // ethnic group-locality and year fixed effects
		est store model_perc`i'_m1
		estadd local TERETH "Yes"
		estadd local ETHYEAR "No"
		estadd local year "Yes"
		estadd local TERYEAR "No"
		* calculate stats
			quietly sum perc`i' if used_d`i' == 1
			estadd scalar outcome_mean = r(mean)
			estfe model_perc`i'_m1, labels(TERETHid "LG-ethnicity FE" year "Year FE" ETHYEARid "Ethnicity-year FE" TERYEARid "LG-year FE")
			drop used*

	* model with ethnic group-locality, ethnic group-year, and locality-year fixed effects
	quietly reghdfe perc`i' `indvar2', absorb(TERETHid ETHYEARid TERYEARid) vce(cluster territory_level) // ethnic group-year and locality-year fixed effects
		est store model_perc`i'_m2
		estadd local TERETH "Yes"
		estadd local ETHYEAR "Yes"
		estadd local year "No"
		estadd local TERYEAR "Yes"
		* calculate stats
			gen used_d`i' = e(sample)
			sum perc`i' if used_d`i' == 1
			estadd scalar outcome_mean = r(mean)
			estfe model_perc`i'_m2, labels(TERETHid "LG-ethnicity FE" year "Year FE" ETHYEARid "Ethnicity-year FE" TERYEARid "LG-year FE")
			drop used*
			drop clerk_first_year_dm

}

* create Table G.6
esttab table1_perchired_m1 table1_perchired_m2 model_perchired_m1 model_perchired_m2 using "table_g6.tex", replace ///
	   booktabs b(3) se(3) eqlabels(none) alignment(c) ///
	   stats(outcome_mean N r2 ///
			 TERETH year ETHYEAR TERYEAR, ///
			 fmt(3 0 3) label("Outcome Mean" "Observations" "R-Squared" ///
				   "Locality-ethnicity FE" "Year FE" "Ethnicity-year FE" "Locality-year FE")) ///
	   label mtitle("Hired" "Hired" "Hired" "Hired") ///
	   varlabels(majority "Majority" clerketh "Clerk ethnicity" la_clerk "Clerk presence" clerk_first_year_dm "Clerk's first year" ///
				 c.majority#c.clerketh "Majority x Clerk ethnicity" c.majority#c.la_clerk "Majority x Clerk presence" c.majority#c.clerk_first_year_dm "Majority x Clerk's first year" ///
				 c.clerketh#c.clerk_first_year_dm "Clerk ethnicity x Clerk's first year" ///
				 c.majority#c.clerketh#c.clerk_first_year_dm "Majority x Clerk ethnicity x Clerk's first year" ///
				 perchiredmiss "Missing indicator" c.majority#c.perchiredmiss "Majority x Missing indicator" ///
				 c.la_clerk#c.perchiredmiss "Clerk presence x Missing indicator" /// 
				 c.majority#c.la_clerk#c.perchiredmiss "Majority x Clerk presence x Missing indicator" ///
				 c.clerketh#c.perchiredmiss "Clerk ethnicity x Missing indicator" ///
				 c.majority#c.clerketh#c.perchiredmiss "Majority x Clerk ethnicity x Missing indicator" ///
				 c.perchiredmiss#c.clerk_first_year_dm "Clerk's first year x Missing indicator" ///
				 c.majority#c.perchiredmiss#c.clerk_first_year_dm "Majority x Clerk's first year x Missing indicator") ///
				 	   collabels(,lhs(Outcome:)) ///
	   keep(majority clerketh la_clerk clerk_first_year_dm ///
			c.majority#c.clerketh c.majority#c.la_clerk c.majority#c.clerk_first_year_dm c.clerketh#c.clerk_first_year_dm ///
			c.majority#c.clerketh#c.clerk_first_year_dm /// 
			perchiredmiss c.majority#c.perchiredmiss ///
			c.la_clerk#c.perchiredmiss /// 
			c.majority#c.la_clerk#c.perchiredmiss ///
			c.clerketh#c.perchiredmiss ///
			c.majority#c.clerketh#c.perchiredmiss ///
			c.perchiredmiss#c.clerk_first_year_dm ///
			c.majority#c.perchiredmiss#c.clerk_first_year_dm) ///
	   star(* 0.10 ** 0.05 *** 0.01) 

* create Table G.7
esttab table1_perchired19_m1 table1_perchired19_m2 model_perchired19_m1 model_perchired19_m2 using "table_g7.tex", replace ///
	   booktabs b(3) se(3) eqlabels(none) alignment(c) ///
	   stats(outcome_mean N r2 ///
			 TERETH year ETHYEAR TERYEAR, ///
			 fmt(3 0 3) label("Outcome Mean" "Observations" "R-Squared" ///
				   "Locality-ethnicity FE" "Year FE" "Ethnicity-year FE" "Locality-year FE")) ///
	   label mtitle("Hired (1-9)" "Hired (1-9)" "Hired (1-9)" "Hired (1-9)" "Hired (1-9)" "Hired (1-9)" "Hired (1-9)" "Hired (1-9)") ///
	   varlabels(majority "Majority" clerketh "Clerk ethnicity" la_clerk "Clerk presence" clerk_first_year_dm "Clerk's first year" ///
				 c.majority#c.clerketh "Majority x Clerk ethnicity" c.majority#c.la_clerk "Majority x Clerk presence" c.majority#c.clerk_first_year_dm "Majority x Clerk's first year" ///
				 c.clerketh#c.clerk_first_year_dm "Clerk ethnicity x Clerk's first year" ///
				 c.majority#c.clerketh#c.clerk_first_year_dm "Majority x Clerk ethnicity x Clerk's first year" ///
				 perchired19miss "Missing indicator (1-9)" c.majority#c.perchired19miss "Majority x Missing indicator (1-9)" ///
				 c.la_clerk#c.perchired19miss "Clerk presence x Missing indicator (1-9)" /// 
				 c.majority#c.la_clerk#c.perchired19miss "Majority x Clerk presence x Missing indicator (1-9)" ///
				 c.clerketh#c.perchired19miss "Clerk ethnicity x Missing indicator (1-9)" ///
				 c.majority#c.clerketh#c.perchired19miss "Majority x Clerk ethnicity x Missing indicator (1-9)" ///
				 c.perchired19miss#c.clerk_first_year_dm "Clerk's first year x Missing indicator (1-9)" ///
				 c.majority#c.perchired19miss#c.clerk_first_year_dm "Majority x Clerk's first year x Missing indicator (1-9)") ///
				 	   collabels(,lhs(Outcome:)) ///
	   keep(majority clerketh la_clerk clerk_first_year_dm ///
			c.majority#c.clerketh c.majority#c.la_clerk c.majority#c.clerk_first_year_dm c.clerketh#c.clerk_first_year_dm ///
			c.majority#c.clerketh#c.clerk_first_year_dm /// 
			perchired19miss c.majority#c.perchired19miss ///
			c.la_clerk#c.perchired19miss /// 
			c.majority#c.la_clerk#c.perchired19miss ///
			c.clerketh#c.perchired19miss ///
			c.majority#c.clerketh#c.perchired19miss ///
			c.perchired19miss#c.clerk_first_year_dm ///
			c.majority#c.perchired19miss#c.clerk_first_year_dm) ///
	   star(* 0.10 ** 0.05 *** 0.01) 

* create Table G.8
esttab table1_perchired1020_m1 table1_perchired1020_m2 model_perchired1020_m1 model_perchired1020_m2 using "table_g8.tex", replace ///
	   booktabs b(3) se(3) eqlabels(none) alignment(c) ///
	   stats(outcome_mean N r2 ///
			 TERETH year ETHYEAR TERYEAR, ///
			 fmt(3 0 3) label("Outcome Mean" "Observations" "R-Squared" ///
				   "Locality-ethnicity FE" "Year FE" "Ethnicity-year FE" "Locality-year FE")) ///
	   label mtitle("Hired (10-20)" "Hired (10-20)" "Hired (10-20)" "Hired (10-20)" "Hired (10-20)" "Hired (10-20)" "Hired (10-20)" "Hired (10-20)") ///
	   varlabels(majority "Majority" clerketh "Clerk ethnicity" la_clerk "Clerk presence" clerk_first_year_dm "Clerk's first year" ///
				 c.majority#c.clerketh "Majority x Clerk ethnicity" c.majority#c.la_clerk "Majority x Clerk presence" c.majority#c.clerk_first_year_dm "Majority x Clerk's first year" ///
				 c.clerketh#c.clerk_first_year_dm "Clerk ethnicity x Clerk's first year" ///
				 c.majority#c.clerketh#c.clerk_first_year_dm "Majority x Clerk ethnicity x Clerk's first year" ///
				 perchired1020miss "Missing indicator (10-20)" c.majority#c.perchired1020miss "Majority x Missing indicator (10-20)" ///
				 c.la_clerk#c.perchired1020miss "Clerk presence x Missing indicator (10-20)" /// 
				 c.majority#c.la_clerk#c.perchired1020miss "Majority x Clerk presence x Missing indicator (10-20)" ///
				 c.clerketh#c.perchired1020miss "Clerk ethnicity x Missing indicator (10-20)" ///
				 c.majority#c.clerketh#c.perchired1020miss "Majority x Clerk ethnicity x Missing indicator (10-20)" ///
				 c.perchired1020miss#c.clerk_first_year_dm "Clerk's first year x Missing indicator (10-20)" ///
				 c.majority#c.perchired1020miss#c.clerk_first_year_dm "Majority x Clerk's first year x Missing indicator (10-20)") ///
				 	   collabels(,lhs(Outcome:)) ///
	   keep(majority clerketh la_clerk clerk_first_year_dm ///
			c.majority#c.clerketh c.majority#c.la_clerk c.majority#c.clerk_first_year_dm c.clerketh#c.clerk_first_year_dm ///
			c.majority#c.clerketh#c.clerk_first_year_dm /// 
			perchired1020miss c.majority#c.perchired1020miss ///
			c.la_clerk#c.perchired1020miss /// 
			c.majority#c.la_clerk#c.perchired1020miss ///
			c.clerketh#c.perchired1020miss ///
			c.majority#c.clerketh#c.perchired1020miss ///
			c.perchired1020miss#c.clerk_first_year_dm ///
			c.majority#c.perchired1020miss#c.clerk_first_year_dm) ///
	   star(* 0.10 ** 0.05 *** 0.01) 

/////
// Table H.1: Hiring with leads
/////

* open local authority-level data
use "localauthority_level.dta", clear 
est clear

* define dependant variable
local depvar hired
	
local indvars // reset indvars 
local indvar2 `" "c.majority##c.la_clerk##c.clerketh##c.perc`depvar'miss la_clerk_lead1 c.la_clerk_lead1#c.majority clerketh_lead1 c.clerketh_lead1#c.majority" "la_clerk_lead2 c.la_clerk_lead2#c.majority clerketh_lead2 c.clerketh_lead2#c.majority" "'
forvalues j = 1/2 {
	local v: word `j' of `indvar2'
	local indvars `indvars' `v'
	
	* model with ethnic group-locality and year fixed effects
	quietly reghdfe perc`depvar' `indvars', absorb(TERETHid year) vce(cluster territory_level) // LA / ethnicity and year FEs, clustered at the LA level
			est store model_perc`depvar'_m`j'
			estadd local TERETH "Yes"
			estadd local ETHYEAR "No"
			estadd local year "Yes"
			estadd local TERYEAR "No"
			gen used_d`depvar'_v`j' = e(sample)
			sum perc`depvar' if used_d`depvar'_v`j' == 1
			estadd scalar outcome_mean = r(mean)
			estfe model_perc`depvar'_m`j', labels(TERETHid "LA-ethnicity FE" year "Year FE" ETHYEARid "Ethnicity-year FE" TERYEARid "LA-year FE")
			drop used*
	}
	
	* model with ethnic group-locality, ethnic group-year, and locality-year fixed effects
	local indvars // reset indvars 
	local indvar2 `" "" "" "c.majority##c.clerketh##c.la_clerk##c.perc`depvar'miss clerketh_lead1 c.clerketh_lead1#c.majority la_clerk_lead1 c.la_clerk_lead1#c.majority" "clerketh_lead2 c.clerketh_lead2#c.majority la_clerk_lead2 c.la_clerk_lead2#c.majority" "'
	forvalues j = 3/4 {
		local v: word `j' of `indvar2'
		local indvars `indvars' `v'
		quietly reghdfe perc`depvar' `indvars', absorb(TERETHid ETHYEARid TERYEARid) vce(cluster territory_level) // LA / ethnicity and year FEs, clustered at the LA level
			est store model_perc`depvar'_m`j'
			estadd local TERETH "Yes"
			estadd local ETHYEAR "Yes"
			estadd local year "No"
			estadd local TERYEAR "Yes"
			gen used_d`depvar'_v`j' = e(sample)
			sum perc`depvar' if used_d`depvar'_v`j' == 1
			estadd scalar outcome_mean = r(mean)
			estfe model_perc`depvar'_m`j', labels(TERETHid "LA-ethnicity FE" year "Year FE" ETHYEARid "Ethnicity-year FE" TERYEARid "LA-year FE")
			drop used*
	}

* create Table H.1 
esttab model_perchired_m1 model_perchired_m2 model_perchired_m3 model_perchired_m4 using "table_h1.tex", replace ///
	   booktabs b(3) se(3) eqlabels(none) alignment(c) ///
	   stats(outcome_mean N r2 ///
			 TERETH year ETHYEAR TERYEAR, ///
			 fmt(3 0 3) label("Outcome Mean" "Observations" "R-Squared" ///
				   "Locality-ethnicity FE" "Year FE" "Ethnicity-year FE" "Locality-year FE")) ///
	   collabels(,lhs(Outcome:)) ///
	   label mtitle("Hired" "Hired" "Hired" "Hired") nonumbers ///
	   varlabels(majority "Majority" la_clerk "Clerk presence" c.majority#c.la_clerk "Majority x Clerk presence" ///
				clerketh "Clerk ethnicity" c.majority#c.clerketh "Majority x Clerk ethnicity" ///
				perchiredmiss "Missing indicator" c.majority#c.perchiredmiss "Majority x Missing indicator" ///
				c.la_clerk#c.perchiredmiss "Clerk presence x Missing indicator" ///
				c.majority#c.la_clerk#c.perchiredmiss "Majority x Clerk presence x Missing indicator" ///
				c.clerketh#c.perchiredmiss "Clerk ethnicity x Missing indicator" ///
				c.majority#c.clerketh#c.perchiredmiss "Majority x Clerk ethnicity x Missing indicator" ///
				la_clerk_lead1 "Clerk presence lead 1" c.la_clerk_lead1#c.majority "Clerk presence lead 1 x Majority" ///
				clerketh_lead1 "Clerk ethnicity lead 1" c.clerketh_lead1#c.majority "Clerk ethnicity lead 1 x Majority" ///
				la_clerk_lead2 "Clerk presence lead 2" c.la_clerk_lead2#c.majority "Clerk presence lead 2 x Majority" ///
				clerketh_lead2 "Clerk ethniciity lead 2" c.clerketh_lead2#c.majority "Clerk ethnicity lead 2 x Majority") ///
	   keep(majority la_clerk c.majority#c.la_clerk clerketh c.majority#c.clerketh ///
			perchiredmiss c.majority#c.perchiredmiss c.la_clerk#c.perchiredmiss ///
			c.majority#c.la_clerk#c.perchiredmiss c.clerketh#c.perchiredmiss ///
			la_clerk_lead1 c.la_clerk_lead1#c.majority ///
			clerketh_lead1 c.clerketh_lead1#c.majority ///
			la_clerk_lead2  c.la_clerk_lead2#c.majority ///
			clerketh_lead2 c.clerketh_lead2#c.majority) ///
	   star(* 0.10 ** 0.05 *** 0.01)	

/////
// Table H.2: Table 3 subset to the five largest ethnic groups in the country. 
/////

* open local authority-level data
use "localauthority_level.dta", clear 
est clear

* define dependant variable
local depvar hired
	
* subset to only top five ethnic groups
keep if ethnicity == "KIKUYU" | ethnicity == "KALENJIN" | ///
		ethnicity == "LUO" | ethnicity == "LUHYA" | ethnicity == "KAMBA"
	
* model with ethnic group-locality and year fixed effects
local indvar "c.majority##c.la_clerk##c.clerketh##c.perc`depvar'miss"
quietly reghdfe perc`depvar' `indvar', absorb(TERETHid year) vce(cluster territory_level) // ethnic group-locality and year fixed effects
		est store model_perc`depvar'_m1
		estadd local TERETH "Yes"
		estadd local ETHYEAR "No"
		estadd local year "Yes"
		estadd local TERYEAR "No"
		* calculate linear combinations and other stats 
			* no clerk and j is non co-ethnic with the council
			summarize perc`depvar' if majority == 0 & la_clerk == 0 & clerketh == 0 
			estadd scalar noclerk_majnoteth = r(mean)				
			* no clerk and j is co-ethnic with the council
			est restore model_perc`depvar'_m1
			lincomest _b[majority] 
			estadd scalar noclerk_majeth = r(estimate)
			estadd scalar noclerk_majeth_se = r(se)
			est store m1_lincom1
			* j is non-coethnic with the clerk and the council
			est restore model_perc`depvar'_m1
			lincomest _b[la_clerk] 
			estadd scalar clerknoteth_majnoteth = r(estimate)
			estadd scalar clerknoteth_majnoteth_se = r(se)
			est store m1_lincom2
			* j is non co-ethnic with the clerk, but co-ethnic with the council
			est restore model_perc`depvar'_m1
			lincomest _b[majority] + _b[la_clerk] + _b[c.majority#c.la_clerk]
			estadd scalar clerknoteth_majeth = r(estimate)
			estadd scalar clerknoteth_majeth_se = r(se)
			est store m1_lincom3
			* j is co-ethnic with the clerk, but not with the council
			est restore model_perc`depvar'_m1
			lincomest _b[la_clerk] + _b[clerketh]
			estadd scalar clerketh_majnoteth = r(estimate)
			estadd scalar clerketh_majnoteth_se = r(se)
			est store m1_lincom4
			* j is co-ethnic with the clerk and the council 
			est restore model_perc`depvar'_m1
			lincomest _b[majority] + _b[la_clerk] + _b[c.majority#c.la_clerk] + _b[clerketh] + _b[c.majority#c.clerketh]
			estadd scalar clerketh_majeth = r(estimate)
			estadd scalar clerketh_majeth_se = r(se)
			est store m1_lincom5
			* outcome mean and other stats
			est restore model_perc`depvar'_m1
			gen used_d`depvar' = e(sample)
			summarize perc`depvar' if used_d`depvar' == 1
			estadd scalar outcome_mean = r(mean)
			est store  model_perc`depvar'_m1					
			estfe model_perc`depvar'_m1, labels(TERETHid "Locality-ethnicity FE" year "Year FE" ETHYEARid "Ethnicity-year FE" TERYEARid "Locality-year FE")
			drop used*
	
* model with ethnic group-locality, ethnic group-year, and locality-year fixed effects
quietly reghdfe perc`depvar' `indvar', absorb(TERETHid ETHYEARid TERYEARid) vce(cluster territory_level) // ethnic group-year and locality-year fixed effects
		est store model_perc`depvar'_m2
		estadd local TERETH "Yes"
		estadd local ETHYEAR "Yes"
		estadd local year "No"
		estadd local TERYEAR "Yes"
		* calculate linear combinations and other stats 
			* no clerk and j is co-ethnic with the council
			est restore model_perc`depvar'_m2
			lincomest _b[majority] 
			estadd scalar noclerk_majeth = r(estimate)
			estadd scalar noclerk_majeth_se = r(se)
			est store m2_lincom1
			* j is non-coethnic with the clerk and the council
			est restore model_perc`depvar'_m2
			lincomest _b[la_clerk] 
			estadd scalar clerknoteth_majnoteth = r(estimate)
			estadd scalar clerknoteth_majnoteth_se = r(se)
			est store m2_lincom2
			* j is non co-ethnic with the clerk, but co-ethnic with the council
			est restore model_perc`depvar'_m2
			lincomest  _b[majority] + _b[la_clerk] + _b[c.majority#c.la_clerk]
			estadd scalar clerknoteth_majeth = r(estimate)
			estadd scalar clerknoteth_majeth_se = r(se)
			est store m2_lincom3
			* j is co-ethnic with the clerk, but not with the council
			est restore model_perc`depvar'_m2
			lincomest _b[la_clerk] + _b[clerketh]
			estadd scalar clerketh_majnoteth = r(estimate)
			estadd scalar clerketh_majnoteth_se = r(se)
			est store m2_lincom4
			* j is co-ethnic with the clerk and the council 
			est restore model_perc`depvar'_m2
			lincomest _b[majority] + _b[la_clerk] + _b[c.majority#c.la_clerk] + _b[clerketh] + _b[c.majority#c.clerketh]
			estadd scalar clerketh_majeth = r(estimate)
			estadd scalar clerketh_majeth_se = r(se)
			est store m2_lincom5
			* outcome mean and other stats
			est restore model_perc`depvar'_m2
			gen used_d`depvar'_v`j' = e(sample)
			sum perc`depvar' if used_d`depvar' == 1
			estadd scalar outcome_mean = r(mean)
			est store model_perc`depvar'_m2
			estfe model_perc`depvar'_m2, labels(TERETHid "Locality-ethnicity FE" year "Year FE" ETHYEARid "Ethnicity-year FE" TERYEARid "Locality-year FE")
			drop used*

* create Table H.2 
esttab model_perchired_m1 model_perchired_m2 using "table_h2.tex", replace ///
	   booktabs b(3) se(3) eqlabels(none) alignment(c) ///
	   stats(outcome_mean N r2 ///
			 TERETH year ETHYEAR TERYEAR, ///
			 fmt(3 0 3) label("Outcome Mean" "Observations" "R-Squared" ///
				   "Locality-ethnicity FE" "Year FE" "Ethnicity-year FE" "Locality-year FE")) ///
	   collabels(,lhs(Outcome:)) ///
	   label mtitle("Hiring" "Hiring") nonumbers ///
	   varlabels(majority "Majority" la_clerk "Clerk presence" c.majority#c.la_clerk "Majority x Clerk presence" ///
				clerketh "Clerk ethnicity" c.majority#c.clerketh "Majority x Clerk ethnicity" ///
				perchiredmiss "Missing indicator" c.majority#c.perchiredmiss "Majority x Missing indicator" ///
				c.la_clerk#c.perchiredmiss "Clerk presence x Missing indicator" ///
				c.majority#c.la_clerk#c.perchiredmiss "Majority x Clerk presence x Missing indicator" ///
				c.clerketh#c.perchiredmiss "Clerk ethnicity x Missing indicator" ///
				c.majority#c.clerketh#c.perchiredmiss "Majority x Clerk ethnicity x Missing indicator") ///
	   keep(majority la_clerk c.majority#c.la_clerk clerketh c.majority#c.clerketh ///
			perchiredmiss c.majority#c.perchiredmiss c.la_clerk#c.perchiredmiss ///
			c.majority#c.la_clerk#c.perchiredmiss c.majority#c.clerketh#c.perchiredmiss c.clerketh#c.perchiredmiss) ///
	   star(* 0.10 ** 0.05 *** 0.01)
	
/////
// Table H.3: Table 3 weighted by the share of each ethnic group in the local authority. 
/////

* open local authority-level data
use "localauthority_level.dta", clear 
est clear

* create a la / year id
egen laeth_id = group(territory_level ethnicity)
	
* find territory_level / ethnic group combos where percent_in_la changes
bysort territory_level ethnicity: egen sd_percent_in_la = sd(percent_in_la)
gen percent_in_la_change = 1 if sd_percent_in_la > 0
replace percent_in_la_change = 0 if percent_in_la_change == .
replace percent_in_la = . if ///
	percent_in_la == 0 & percent_in_la_change == 1 
xfill percent_in_la, i(laeth_id)
drop laeth_id sd_percent_in_la percent_in_la_change
	
* normalize weights
bysort territory_level year: egen sum_weight = total(percent_in_la)
gen percent_in_la_norm = (percent_in_la / sum_weight)

* define dependant variable
local depvar hired
	
* model with ethnic group-locality and year fixed effects
local indvar "c.majority##c.la_clerk##c.clerketh##c.perc`depvar'miss"
quietly reghdfe perc`depvar' `indvar' [aweight = percent_in_la_norm], absorb(TERETHid year) vce(cluster territory_level) // ethnic group-locality and year fixed effects
		est store model_perc`depvar'_m1
		estadd local TERETH "Yes"
		estadd local ETHYEAR "No"
		estadd local year "Yes"
		estadd local TERYEAR "No"
		* calculate linear combinations and other stats 
			* no clerk and j is non co-ethnic with the council
			est restore model_perc`depvar'_m1
			summarize perc`depvar' if majority == 0 & la_clerk == 0 & clerketh == 0 
			estadd scalar noclerk_majnoteth = r(mean)				
			* no clerk and j is co-ethnic with the council
			est restore model_perc`depvar'_m1
			lincomest _b[majority] 
			estadd scalar noclerk_majeth = r(estimate)
			estadd scalar noclerk_majeth_se = r(se)
			est store m1_lincom1
			* j is non-coethnic with the clerk and the council
			est restore model_perc`depvar'_m1
			lincomest _b[la_clerk] 
			estadd scalar clerknoteth_majnoteth = r(estimate)
			estadd scalar clerknoteth_majnoteth_se = r(se)
			est store m1_lincom2
			* j is non co-ethnic with the clerk, but co-ethnic with the council
			est restore model_perc`depvar'_m1
			lincomest _b[majority] + _b[la_clerk] + _b[c.majority#c.la_clerk]
			estadd scalar clerknoteth_majeth = r(estimate)
			estadd scalar clerknoteth_majeth_se = r(se)
			est store m1_lincom3
			* j is co-ethnic with the clerk, but not with the council
			est restore model_perc`depvar'_m1
			lincomest _b[la_clerk] + _b[clerketh]
			estadd scalar clerketh_majnoteth = r(estimate)
			estadd scalar clerketh_majnoteth_se = r(se)
			est store m1_lincom4
			* j is co-ethnic with the clerk and the council 
			est restore model_perc`depvar'_m1
			lincomest _b[majority] + _b[la_clerk] + _b[c.majority#c.la_clerk] + _b[clerketh] + _b[c.majority#c.clerketh]
			estadd scalar clerketh_majeth = r(estimate)
			estadd scalar clerketh_majeth_se = r(se)
			est store m1_lincom5
			* outcome mean and other stats
			est restore model_perc`depvar'_m1
			gen used_d`depvar' = e(sample)
			summarize perc`depvar' if used_d`depvar' == 1
			estadd scalar outcome_mean = r(mean)
			est store model_perc`depvar'_m1
			estfe model_perc`depvar'_m1, labels(TERETHid "Locality-ethnicity FE" year "Year FE" ETHYEARid "Ethnicity-year FE" TERYEARid "Locality-year FE")
			drop used*
	
* model with ethnic group-locality, ethnic group-year, and locality-year fixed effects
quietly reghdfe perc`depvar' `indvar' [aweight = percent_in_la_norm], absorb(TERETHid ETHYEARid TERYEARid) vce(cluster territory_level) // ethnic group-locality and ethnic group-year fixed effects
		est store model_perc`depvar'_m2
		estadd local TERETH "Yes"
		estadd local ETHYEAR "Yes"
		estadd local year "No"
		estadd local TERYEAR "Yes"
		* calculate linear combinations and other stats 
			* no clerk and j is co-ethnic with the council
			est restore model_perc`depvar'_m2
			lincomest _b[majority] 
			estadd scalar noclerk_majeth = r(estimate)
			estadd scalar noclerk_majeth_se = r(se)
			est store m2_lincom1
			* j is non-coethnic with the clerk and the council
			est restore model_perc`depvar'_m2
			lincomest _b[la_clerk] 
			estadd scalar clerknoteth_majnoteth = r(estimate)
			estadd scalar clerknoteth_majnoteth_se = r(se)
			est store m2_lincom2
			* j is non co-ethnic with the clerk, but co-ethnic with the council
			est restore model_perc`depvar'_m2
			lincomest  _b[majority] + _b[la_clerk] + _b[c.majority#c.la_clerk]
			estadd scalar clerknoteth_majeth = r(estimate)
			estadd scalar clerknoteth_majeth_se = r(se)
			est store m2_lincom3
			* j is co-ethnic with the clerk, but not with the council
			est restore model_perc`depvar'_m2
			lincomest _b[la_clerk] + _b[clerketh]
			estadd scalar clerketh_majnoteth = r(estimate)
			estadd scalar clerketh_majnoteth_se = r(se)
			est store m2_lincom4
			* j is co-ethnic with the clerk and the council 
			est restore model_perc`depvar'_m2
			lincomest _b[majority] + _b[la_clerk] + _b[c.majority#c.la_clerk] + _b[clerketh] + _b[c.majority#c.clerketh]
			estadd scalar clerketh_majeth = r(estimate)
			estadd scalar clerketh_majeth_se = r(se)
			est store m2_lincom5
			* outcome mean and other stats
			est restore model_perc`depvar'_m2
			gen used_d`depvar'_v`j' = e(sample)
			sum perc`depvar' if used_d`i' == 1
			estadd scalar outcome_mean = r(mean)
			est store model_perc`depvar'_m2
			estfe model_perc`depvar'_m2, labels(TERETHid "Locality-ethnicity FE" year "Year FE" ETHYEARid "Ethnicity-year FE" TERYEARid "Locality-year FE")
			drop used*
		
* create Table H.3
esttab model_perchired_m1 model_perchired_m2 using "table_h3.tex", replace ///
	   booktabs b(3) se(3) eqlabels(none) alignment(c) ///
	   stats(outcome_mean N r2 ///
			 TERETH year ETHYEAR TERYEAR, ///
			 fmt(3 0 3) label("Outcome Mean" "Observations" "R-Squared" ///
				   "Locality-ethnicity FE" "Year FE" "Ethnicity-year FE" "Locality-year FE")) ///
	   collabels(,lhs(Outcome:)) ///
	   label mtitle("Hiring" "Hiring") nonumbers ///
	   varlabels(majority "Majority" la_clerk "Clerk presence" c.majority#c.la_clerk "Majority x Clerk presence" ///
				clerketh "Clerk ethnicity" c.majority#c.clerketh "Majority x Clerk ethnicity" ///
				perchiredmiss "Missing indicator" c.majority#c.perchiredmiss "Majority x Missing indicator" ///
				c.la_clerk#c.perchiredmiss "Clerk presence x Missing indicator" ///
				c.majority#c.la_clerk#c.perchiredmiss "Majority x Clerk presence x Missing indicator" ///
				c.clerketh#c.perchiredmiss "Clerk ethnicity x Missing indicator" ///
				c.majority#c.clerketh#c.perchiredmiss "Majority x Clerk ethnicity x Missing indicator") ///
	   keep(majority la_clerk c.majority#c.la_clerk clerketh c.majority#c.clerketh ///
			perchiredmiss c.majority#c.perchiredmiss c.la_clerk#c.perchiredmiss ///
			c.majority#c.la_clerk#c.perchiredmiss c.majority#c.clerketh#c.perchiredmiss c.clerketh#c.perchiredmiss) ///
	   star(* 0.10 ** 0.05 *** 0.01)


